In the execution of graphics workloads by a graphics processing unit in a computing system, an application through the operating system (OS) submits a workload to a graphics driver. The graphics driver configures the workload so that the graphics processing unit can execute it. Each workload can be partitioned into multiple graphics applications which are also referred to as contexts. Each context runs through each stage of a pipeline of the graphics processing hardware to render graphics on a display. The graphics driver assigns a unique context ID (Identifier) for each graphics application. Each time an application submits a workload to the graphics driver, the graphics driver identifies it with the context ID and then submits it to the graphics processing unit (GPU).
The graphics processing unit executes each context until the context is completed or until the context is interrupted. The graphics hardware detects a context switch when a sequence of instructions in the context comes to a change in the context ID. A context may be switched out by the graphics driver for any of a variety of different reasons. A particular context may be preempted by a higher priority context. A context may be switched out if it stalls because of a wait for events. This allows another context to be executed while the stalled context continues to wait. A context may also be switched out so that another context can produce intermediate results that are required by the context to continue executing. The switching out of one context and switching in of another context is referred to as an indirection.
When the context is switched out, the current state of the context is saved by the hardware. When the context is switched back in, the saved state is restored by the hardware. The saved context state contains the hardware state of the context at the point of context switch. This includes graphics addresses for surfaces that are exercised by the context (e.g. vertex buffers, stream out buffers, depth buffers, render target, sampler textures maps, kernel state pointers for various shaders, etc.).
The addresses used to store graphics memory surfaces are pinned. As long as an application is running, the graphics memory surfaces remain intact and can be used as is on when the context is resubmitted by the graphics driver to the GPU.